package com.wash.shoes.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.StringUtils;
import com.wash.shoes.domain.dto.ShopPageDto;
import com.wash.shoes.entity.ShopPo;
import com.wash.shoes.mapper.ShopMapper;
import com.wash.shoes.page.PageFactory;
import com.wash.shoes.service.ShopService;
import com.wash.shoes.util.HeaderUtil;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 店铺系统的店铺 服务实现类
 * </p>
 *
 * @author zhengyunpeng
 * @since 2024-08-27
 */
@Service
public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPo> implements ShopService {

    /**
     * 获取所有抖音启用店铺的poid
     *
     * @param brandId
     * @return
     */
    @Override
    public List<String> getAllDyPoidWithBrandId(String brandId) {
        if (brandId == null) {
            return Collections.emptyList();
        }
        return baseMapper.getAllDyPoidWithBrandId(brandId);
    }

    @Override
    public Page<ShopPo> pageList(ShopPageDto shopPo) {
        Page page = PageFactory.defaultPage();
        List<ShopPo> dataList = baseMapper.pageList(page, shopPo);
        page.setRecords(dataList);
        return page;
    }

    @Override
    public ShopPo getShopByName(String shopName) {
        return this.baseMapper.getShopByName(shopName);
    }

    @Override
    public ShopPo getByOpBizCode(String opBizCode) {
        return this.baseMapper.getByOpBizCode(opBizCode);
    }

    @Override
    public List<ShopPo> getAllShop() {
        return this.baseMapper.getAllShop();
    }

    @Override
    public ShopPo getOneShopByProvinces(String provinces, String city, String channel, String brandId) {
        if (StringUtils.isNotEmpty(city)) {
            city = city.replace("市", "");
        }
        return this.baseMapper.getOneShopByProvinces(provinces, city, channel, brandId);
    }

    @Override
    public String getShopIdByPoId(String poId) {
        return this.baseMapper.getShopIdByPoId(poId);
    }

    @Override
    public String getPoIdByShopId(String shopId) {
        return this.baseMapper.getPoIdByShopId(shopId);
    }

    /**
     * 根据shopId查询店铺信息
     *
     * @return
     */
    public List<ShopPo> getShopByShopIds() {
        String shopIdStr = HeaderUtil.getShopIdStr();
        return this.baseMapper.getShopByShopIds(shopIdStr);
    }
}
